﻿<ui:View x:Class="CPPEI.Coolzon.Designer.Views.ToolboxView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:ui="clr-namespace:CPPEI.Coolzon.UI;assembly=CPPEI.Coolzon.UI"
             xmlns:local="clr-namespace:CPPEI.Coolzon.Metadata;assembly=CPPEI.Coolzon.Metadata"
             xmlns:views="clr-namespace:CPPEI.Coolzon.Designer.Views"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <views:TypeToIconSourceConverter x:Key="_typeToIconSourceConverter"/>
        <Style x:Key="TileStyle" TargetType="{x:Type ListView}">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate DataType="{x:Type local:PartLibItem}">
                        <Grid Height="72" Width="65" Margin="3">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="40"/>
                                <RowDefinition Height="*"/>
                            </Grid.RowDefinitions>
                            <Image Grid.Row="0" Source="{Binding BindsDirectlyToSource=True,Converter={StaticResource _typeToIconSourceConverter}}" Width="40" Height="40"/>
                            <TextBlock Grid.Row="1" TextWrapping="Wrap" MaxWidth="68" FontSize="13" VerticalAlignment="Center" TextAlignment="Center" Text="{Binding Path=Caption}"></TextBlock>
                        </Grid>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal" MaxWidth="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type ListView}}, Path=ActualWidth}"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ListStyle" TargetType="{x:Type ListView}">
            <Setter Property="ItemTemplate">
                <Setter.Value>
                    <DataTemplate DataType="{x:Type local:PartLibItem}">
                        <TextBlock Grid.Row="1"  FontSize="13" VerticalAlignment="Center" TextAlignment="Left" Text="{Binding Path=Caption}"></TextBlock>
                    </DataTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <StackPanel Orientation="Vertical" MaxWidth="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorLevel=1, AncestorType={x:Type ListView}}, Path=ActualWidth}"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <ListView x:Name="toolList" SelectionChanged="toolList_SelectionChanged" Style="{StaticResource TileStyle}" >
            <ListView.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander IsExpanded="True">
                                            <Expander.Header>
                                                <TextBlock Text="{Binding Path=Name}"/>
                                            </Expander.Header>
                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <DataGridRowsPresenter />
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </ListView.GroupStyle>
            <ListView.ContextMenu>
                <ContextMenu >
                    <MenuItem Header="查看">
                        <MenuItem Header="列表" Click="MenuItemList_Click"/>
                        <MenuItem Header="平铺" Click="MenuItemTile_Click"/>
                    </MenuItem>
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>

    </Grid>
</ui:View>
